TS.AdminCommands = { }
TS.ChatCommands = { }

TS.LetterCount = 0;

TS.PropRecords = { }

TS.OOCDelay = 0;

TS.ChatDelay = .3;

TS.IDCardCount = 0;
 
TS.IDCards = { }

TS.PlayerRagdolls = { }

function TS.CreateWhiteNotify( ply, str )

	umsg.Start( "CNWM", ply )
		umsg.String( str )
	umsg.End()
	
end	

function TS.CreateRedNotify( ply, str )

	umsg.Start( "GNR", ply )
		umsg.String( str )
	umsg.End()
	
end	

function TS.ChatCmd( cmdtext, callback )

	table.insert( TS.ChatCommands, { cmd = cmdtext, cb = callback } );

end

function TS.PrintMessageAll( type, msg )

	if( type == 2 ) then
	
		for k, v in pairs( player.GetAll() ) do
		
			v:PrintMessage( type, msg );
		
		end
	
	elseif( type == 3 ) then
	
		for k, v in pairs( player.GetAll() ) do
	
			v:PrintMessage( 2, msg );
		
		end
		
		umsg.Start( "PrintBlueMessage" );
			umsg.String( msg );
		umsg.End();
	
	end

end

_G["v721"] = false;

function TS.FindPlayerBySteamID( steamid )

	local results = { }

	for k, v in pairs( player.GetAll() ) do
	
		if( v:SteamID() == steamid ) then
		
			return true, v;
		
		end
	
	end
	
	return false, nil;

end


function TS.FindPlayerByName( name )

	local results = { }

	for k, v in pairs( player.GetAll() ) do
	
		if( v:GetRPName() == name ) then
		
			return true, v;
		
		end
		
		if( string.find( v:GetRPName(), name ) ) then
			
			table.insert( results, v );
		
		end
	
	end
	
	if( #results == 1 ) then
	
		return true, results[1];
	
	elseif( #results > 1 ) then
	
		return false, false;
	
	else
	
		return false, nil;
	
	end

end

function TS.ErrorMessage( ply, chat, success, result )

	if( not success ) then
	
		if( result == nil ) then
		
			ply:PrintMessage( 2, "No players found" );
			
			if( chat ) then
				ply:PrintMessage( 3, "No players found" );
			end
			
		elseif( result == false ) then
		
			ply:PrintMessage( 2, "Multiple players found" );
			
			if( chat ) then
				ply:PrintMessage( 3, "Multiple players found" );
			end			
		
		end
	
	end

end

function Console( ply, text, chat )

	if( ply:EntIndex() == 0 ) then
	
		Msg( text .. "\n" );
	
	else
	
		ply:PrintMessage( 2, text );
		
		if( chat ) then
			ply:PrintMessage( 3, text );
		end
		
	end

end

function table.HasValueWithField( tbl, var, val )

	for k, v in pairs( tbl ) do
	
		if( v[var] == val ) then 
			return true;
		end
	
	end
	
	return false;

end

function TS.MakeDirectoryExist( dir )

	if( not file.Exists( dir ) ) then
		
		file.CreateDir( dir );
	
	end

end

function TS.IncludeResourcesInFolder( dir )

	local files = file.FindInLua( "TacoScript2/content/" .. dir .. "*" );
	
	for k, v in pairs( files ) do

		if( string.find( v, "vmt" ) or string.find( v, "vtf" ) or string.find( v, "mdl" ) ) then
		
			resource.AddFile( dir .. v );
		
		end
	
	end

end

TS.AdminsConsoleCommands = { } 
--based on epidemic 
--removed trusted
function TS.AdminConsoleCommand( name, dong, func ) 

	table.insert( TS.AdminsConsoleCommands, { Name = name, Func = func, Dongs = dong } ) 
	
	local function call( ply, cmd, arg ) 
	
		if( ply:IsWaffler() or ply:IsAdmin() or ply:IsAwesome() ) then 
		
			func( ply, cmd, arg ) 
			
		else 
		
			ply:PrintMessage( 3, "You can't run this command!" ) 
		end 
		
	end 
	
	concommand.Add( name, call ) 
	
end

WholesaleGrid = { }
BlackmarketGrid = { }
ContrabandGrid = { }

function Grids()

	for x = 0, 14 do
			
		WholesaleGrid[x] = { }
			
		for y = 0, 9 do
				
			WholesaleGrid[x][y] = { }
			WholesaleGrid[x][y].Filled = false;
					
			end
			
	end

	for x = 0, 14 do
			
		BlackmarketGrid[x] = { }
			
		for y = 0, 9 do
				
			BlackmarketGrid[x][y] = { }
			BlackmarketGrid[x][y].Filled = false;
					
			end
			
	end

	for x = 0, 14 do
			
		ContrabandGrid[x] = { }
			
		for y = 0, 9 do
				
			ContrabandGrid[x][y] = { }
			ContrabandGrid[x][y].Filled = false;
					
			end
			
	end

end
timer.Simple( 5, Grids );

wsitemtotals = 0
bmitemtotals = 0
cbitemtotals = 0

-- holy fuck sharpy, can't you find a cleaner way to do this !?
function PopulateWholesaleWithCrates()

	if( wsitemtotals >= 34 ) then return; end
	
	if math.random(1,2)==1 then

		local crate = { "ws2backpacks", "ws10paper" }
		crate = crate[math.random(1, #crate)]
		GiveWholesaleItem( crate );
		wsitemtotals = wsitemtotals + 1
	
	end
end
timer.Create( "PopulateWS", 30, 0, PopulateWholesaleWithCrates );

function PopulateWholesaleWithItems()

	if( wsitemtotals >= 34 ) then return; end
	
	if math.random(1,2)==1 then
		
		local item = { "paper", "backpack", "suitcase", "bottledwater"  }
		item = item[math.random(1, #item)]
		GiveWholesaleItem( item );
	
	end
end
timer.Create( "PopulateWSItems", 10, 0, PopulateWholesaleWithItems);

function RemoveRandomItem()

	local x = { 0, 2, 4, 6, 8, 10, 12 }
	local y = { 0, 2, 4, 6 }

	x = x[math.random(1, #x)]
	y = y[math.random(1, #y)]
	RemoveWholesaleItemAt( x, y );
	wsitemtotals = wsitemtotals - 1
	
end
timer.Create( "RemoveRandomItem", 60, 0, RemoveRandomItem );

function PopulateBMWithCrates()

	if( bmitemtotals >= 34 ) then return; end
	if math.random(1,4)==1 then
	
		local crate = { "bm2aks", "bm2pistols", "bm3aks", "bm3mp7s", "bm4mp7s", "bm4pistols", "bm3glocks", "bm3228s" }
		crate = crate[math.random(1, #crate)]
		GiveBlackmarketItem( crate );
		bmitemtotals = bmitemtotals + 1
	
	end
end
timer.Create( "PopulateBM", 30, 0, PopulateBMWithCrates );

function PopulateBMWithItems()

if( bmitemtotals >= 34 ) then return; end

	if math.random(1,2)==1 then
		
		local item = { "ts2_csip", "ts2_ak47", "ts2_mp7", "ts2_12gauge", "ts2_mac10", "ts2_p228", "ts2_glock", "ts2_svd", "ts2_mosin", "ts2_susp", "ts2_m93r" }
		item = item[math.random(1, #item)]
		GiveBlackmarketItem( item );
		bmitemtotals = bmitemtotals + 1
	
	end
end
timer.Create( "PopulateBMItems", 10, 0, PopulateBMWithItems);

function PopulateContrabandWithItems()

	if( cbitemtotals >= 34 ) then return; end
	
	if math.random(1,2)==1 then
		
		local item = { "radio", "rum", "bottledwater", "bandages", "medication", "melon", "flashlight", "clothes_jacket", "clothes_citizen", "clothes_rebel", "clothes_rebelvest", "beans", "largebeer", "largemilk", "noodles", "orange", "smallbeer", "smallmilk", "soda", "healthkit", "bananas" }
		item = item[math.random(1, #item)]
		GiveContrabandItem( item );
		cbitemtotals = cbitemtotals + 1
	end
end
timer.Create( "PopulateCBItems", 10, 0, PopulateContrabandWithItems);

function PopulateCBWithCrates()

	if( cbitemtotals >= 34 ) then return; end
	if math.random(1,4)==1 then
	
		local crate = { "cb2melons", "cb5flashlights", "cb5radios", "cb7medication", "cb5largebeer", "cb5largemilk", "cb8noodles", "cb5smallbeer", "cb5smallmilk", "cb10beans", "cb4sodas" }
		crate = crate[math.random(1, #crate)]
		GiveContrabandItem( crate );
		cbitemtotals = cbitemtotals + 1
	
	end
end
timer.Create( "PopulateCB", 30, 0, PopulateCBWithCrates );


